import java.util.Scanner;
import java.util.Stack;
/**
 * Created by Peter_Z.
 * <p>
 * Date: 2023/8/21 0021
 */
public class Test {
        Stack<Integer> stack = new Stack<>();
        Stack<Integer> maxStack = new Stack<>();
        public void push(int e){
            stack.push(e);
            if (maxStack.empty() || e > maxStack.peek()){
                maxStack.push(e);
            }else if (e < maxStack.peek()){
                maxStack.push(maxStack.peek());
            }
        }
        //pop时要注意栈是否为空
        public int pop(){
            if (!stack.empty()&&!maxStack.empty()){
                int e = stack.pop();
                maxStack.pop();
                return e;
            }
            else {
                System.out.println("栈为空！");
                return 0;
            }
        }
        public int getMax(){
            return maxStack.peek();
        }
}


